import os

from get_data.get_autor import get_all_author
from get_data.get_data_robot import get_html_source
from get_data.get_img_time import get_all_time_start
from get_data.get_tag_url import get_all_tag
from get_data.get_url import get_url
from get_data.write_in_csv import write_csv, write_mysql

url = 'https://www.vilipix.com'
headers = {
        'User-Agent':
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.69',
        'Cookie':
            'auth.strategy=local; Hm_lvt_7246eb56b79171a6fe5284a8bf523aa0=1694076593,1694081519,1694141021,1694154244; Hm_lpvt_7246eb56b79171a6fe5284a8bf523aa0=1694154244'
    }

if __name__ == "__main__":
    # [{}, {}] {名，喜欢人数}
    img_list_like = []
    # [{}, {}] {名，id}
    img_id_list = []
    # 图片下载链接
    img_url = []
    rank_t = input('时间')
    rank_s = input('daily or weekly or monthly')
    get_html_source(url, headers, rank_t, rank_s, img_list_like, img_id_list, img_url)
    print(img_list_like)
    print(img_id_list)
    print(img_url)
    #  得到图片详情页链接
    url_front = 'https://www.vilipix.com/illust/'
    url_list = get_url(url_front, img_id_list)
    print(url_list)
    #  得到作者名和id
    autor_name_data = []
    author_id_list = []
    get_all_author(url_list, headers, autor_name_data, author_id_list)
    print(autor_name_data)
    print(author_id_list)
    #  得到时间
    time_data = []
    get_all_time_start(url_list, headers, time_data)
    print(time_data)
    #  得到tag
    tag_name_data = []
    get_all_tag(url_list, headers, tag_name_data)
    print(tag_name_data)
    # 写入csv和数据库
    write_csv(autor_name_data, img_list_like, tag_name_data, time_data, url_list, img_url)
    write_mysql()
    print('写入完成')




